<template>
	<view class="userLayout pageBg">
		<view style="height: 15%; width: 100%; opacity: 0;">
		  这是隐藏的文字,嘿嘿嘿
		</view>

		<view class="userInfo" v-if="userInfo">
			<view class="avatar">
				<image src="/common/images/feishu_5.webp" mode="aspectFill"></image>
			</view>
			<view class="ip">
				{{ userInfo.IP }}
			</view>
			<view class="address">
				来自于: {{ userInfo.address?.city || userInfo.address?.province || userInfo.address?.country || '未知位置' }}
			</view>
		</view>

		<view class="section">
			<view class="list">
				<navigator url="/pages/downLoadList/downLoadList?name=我的下载" open-type="reLaunch">
					<view class="row">
						<view class="left">
							<uni-icons type="download-filled" size="20" color="#28b389" />
							<view class="text">我的下载</view>
						</view>
						<view class="right">
							<uni-icons type="right" size="15" color="#aaa" />
							<view class="text">{{ downloadCount }}</view>
						</view>
					</view>
				</navigator>

				<navigator url="/pages/sortList/sortList?name=评分" open-type="reLaunch">
					<view class="row">
						<view class="left">
							<uni-icons type="download-filled" size="20" color="#28b389" />
							<view class="text">我的评分</view>
						</view>
						<view class="right">
							<uni-icons type="right" size="15" color="#aaa" />
							<view class="text">{{ scoreCount }}</view>
						</view>
					</view>
				</navigator>

				<navigator url="/pages/selectWhichToEat/selectWhichToEat?name=吃点什么呢" open-type="reLaunch">
					<view class="row">
						<view class="left">
							<uni-icons type="download-filled" size="20" color="#28b389" />
							<view class="text">吃点什么</view>
						</view>
						<view class="right">
							<uni-icons type="right" size="15" color="#aaa" />
						</view>
					</view>
				</navigator>

				<navigator url="/pages/chatPage/chatPage?name=聊点什么呢" open-type="reLaunch">
					<view class="row">
						<view class="left">
							<uni-icons type="download-filled" size="20" color="#28b389" />
							<view class="text">聊点什么</view>
						</view>
						<view class="right">
							<uni-icons type="right" size="15" color="#aaa" />
						</view>
					</view>
				</navigator>
				<navigator url="/pages/chatwithsamllxhy/chatwithsamllxhy?name=和smallxhy聊天" open-type="reLaunch">
					<view class="row">
						<view class="left">
							<uni-icons type="download-filled" size="20" color="#28b389" />
							<view class="text">和smallxhy</view>
						</view>
						<view class="right">
							<uni-icons type="right" size="15" color="#aaa" />
						</view>
					</view>
				</navigator>
				
				<!-- <navigator url="/pages/character_1/character_1?name=看character" open-type="reLaunch">
					<view class="row">
						<view class="left">
							<uni-icons type="download-filled" size="20" color="#28b389" />
							<view class="text">和character</view>
						</view>
						<view class="right">
							<uni-icons type="right" size="15" color="#aaa" />
						</view>
					</view>
				</navigator> -->

				<view class="row">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28b389" />
						<view class="text">联系客服</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa" />
					</view>

					<!-- #ifdef MP -->
					<button open-type="contact">联系客服</button>
					<!-- #endif -->

					<!-- #ifdef H5 -->
					<button @click="clickContact">拨打电话</button>
					<!-- #endif -->
				</view>
			</view>
		</view>

		<view class="section">
			<view class="list">
				<view class="row">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28b389" />
						<view class="text">订阅</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa" />
					</view>
				</view>
				<view class="row">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28b389" />
						<view class="text">常见问题</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa" />
					</view>
				</view>
			</view>
		</view>

		<view style="padding: 80rpx 0;">
			<uni-load-more status="loading" />
		</view>
	</view>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { apiGetUserInfo_ctt } from '@/api/api_ctt.js'

// 用户信息
const userInfo = ref(null)

const clickContact = () => {
	uni.makePhoneCall({
		phoneNumber: '17858798607'
	})
}

const getUserInfo = async () => {
	try {
		const res = await apiGetUserInfo_ctt()
		userInfo.value = res.data?.[0] || null
	} catch (e) {
		console.error('获取用户信息失败:', e)
	}
}

const downloadCount = computed(() => {
	return Array.isArray(userInfo.value?.downloadSize)
		? userInfo.value.downloadSize.length
		: 0
})

const scoreCount = computed(() => {
	return Array.isArray(userInfo.value?.scoreSize)
		? userInfo.value.scoreSize.reduce((sum, item) => sum + Number(item.score || 0), 0)
		: 0
})

onMounted(() => {
	getUserInfo()
})
</script>

<style lang="scss" scoped>
	.userLayout{
		.userInfo{
			display: flex;
			align-items: center;
			flex-direction: column;
			padding: 50rpx 0;
			.avatar{
				width: 160rpx;
				height: 160rpx;
				border-radius: 50%;
				overflow: hidden;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.ip{
				font-size: 44rpx;
				color: #333;
				padding: 20rpx 0 5rpx;
			}
			.address{
				font-size: 28rpx;
				color:"#aaa"
			}
		}
		.section{
			width: 690rpx;
			margin: 50rpx auto;
			border: 1px solid #eee;
			border-radius: 10rpx;
			box-shadow: 0 0 30rpx rgba(0,0,0,0.05);
			.list{
				.row{
					display: flex;
					align-items: center;
					position: relative;
					justify-content: space-between;
					padding: 0 30rpx;
					height:100rpx;
					border:1px solid #eee;
					background: #fff;
					&:last-child{border-bottom: 0;}
					.left{
						display: flex;
						align-items: center;
						.text{
							padding-left: 20rpx;
							color: #666;
						}
					}
					.right{
						display: flex;
						align-items: center;
						.text{
							font-size: 28rpx;
							color: #333;
						}
					}
					button{
						position: absolute;
						top:0;
						left:0;
						height: 100rpx;
						width: 100%;
						opacity: 0;
					}
				}
			}
		}
	}
	
</style>
